<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\adminuser\controller;

class AdminUser extends \app\AdminRest
{
    protected $model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\adminuser\model\AdminUser();
    }
    public function configInfo()
    {
        $input = $this->_param;
        $dis = ["uniacid" => $this->_uniacid];
        $data = $this->model->dataInfo($dis, 1);
        if(!empty($data["user_id"])) {
            $user_model = new \app\massage\model\User();
            $data["user_info"] = $user_model->where(["id" => $data["user_id"]])->field("id,nickName,avatarUrl")->find();
        }
        $comm_model = new \app\massage\model\Commission();
        $wallet_model = new \app\massage\model\Wallet();
        $data["total_cash"] = $comm_model->where(["status" => 2, "type" => 16])->sum("company_cash");
        $data["wallet_cash"] = $wallet_model->where(["type" => 11])->where("status", "in", [2])->sum("total_price");
        $data["total_cash"] = round($data["total_cash"], 2);
        $data["wallet_cash"] = round($data["wallet_cash"], 2);
        return $this->success($data);
    }
    public function configUpdate()
    {
        $input = $this->_input;
        if(empty($input["phone_code"])) {
            $this->errorMsg("请输入验证码");
        }
        $phone = getConfigSetting($this->_uniacid, "login_auth_phone");
        $key = $phone . "SendAdminShortMsg";
        if($input["phone_code"] != getCache($key, $this->_uniacid)) {
            $this->errorMsg("验证码错误");
        }
        setCache($key, "", 10, $this->_uniacid);
        $dis = ["uniacid" => $this->_uniacid];
        $update = ["user_id" => $input["user_id"], "phone" => $input["phone"], "user_name" => $input["user_name"], "bind_time" => time()];
        $data = $this->model->dataUpdate($dis, $update);
        return $this->success($data);
    }
    public function checkPhoneCode()
    {
        $input = $this->_input;
        $key = $input["phone"] . "bindadminuser";
        if(empty($input["phone_code"])) {
            $this->errorMsg("请输入验证码");
        }
        if($input["phone_code"] != getCache($key, $this->_uniacid)) {
            $this->errorMsg("验证码错误");
        }
        setCache($key, "", 10, $this->_uniacid);
        return $this->success(true);
    }
    public function bindsendPhoneCode()
    {
        $input = $this->_input;
        $config = new \app\massage\model\ShortCodeConfig();
        $key = "bindadminuser";
        $res = $config->sendSmsCode($input["phone"], $this->_uniacid, $key);
        if(!empty($res["Message"]) && $res["Message"] == "OK") {
            return $this->success(1);
        }
        return $this->error($res["Message"]);
    }
    public function delbind()
    {
        $input = $this->_input;
        $data = $this->model->dataInfo(["uniacid" => $this->_uniacid]);
        $key = $data["phone"] . "delbindadminuser";
        if(empty($input["phone_code"])) {
            $this->errorMsg("请输入验证码");
        }
        if($input["phone_code"] != getCache($key, $this->_uniacid)) {
            $this->errorMsg("验证码错误");
        }
        $dis = ["uniacid" => $this->_uniacid];
        $update = ["user_id" => "", "phone" => ""];
        $data = $this->model->dataUpdate($dis, $update);
        return $this->success($data);
    }
    public function delBindsendPhoneCode()
    {
        $input = $this->_input;
        $config = new \app\massage\model\ShortCodeConfig();
        $data = $this->model->dataInfo(["uniacid" => $this->_uniacid]);
        if(empty($data["phone"])) {
            $this->errorMsg("还未绑定人员");
        }
        $key = "delbindadminuser";
        $res = $config->sendSmsCode($data["phone"], $this->_uniacid, $key);
        if(!empty($res["Message"]) && $res["Message"] == "OK") {
            return $this->success(1);
        }
        return $this->error($res["Message"]);
    }
    public function sendAdminShortMsg()
    {
        $input = $this->_input;
        $config = new \app\massage\model\ShortCodeConfig();
        $phone = getConfigSetting($this->_uniacid, "login_auth_phone");
        $key = "SendAdminShortMsg";
        $res = $config->sendSmsCode($phone, $this->_uniacid, $key);
        if(!empty($res["Message"]) && $res["Message"] == "OK") {
            return $this->success(1);
        }
        return $this->error($res["Message"]);
    }
}

?>